home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / PERL.SPK / Perl5001 / Manual / perl next >
Text File  |  1995-04-18  |  12KB  |  283 lines

  1. <!-- $RCSfile$$Revision$$Date$ -->
  2. <!-- $Log$ -->
  3. <HTML>
  4. <TITLE> PERL </TITLE>
  5. <h2>NAME</h2>
  6. perl - Practical Extraction and Report Language
  7. <p><h2>SYNOPSIS</h2>
  8. For ease of access, the Perl manual has been split up into a number
  9. of sections:
  10. <p>
  11. <ul>
  12. <li><A HREF="perl.html">perl</A>    Perl overview (this section)
  13. <li><A HREF="perldata.html">perldata</A>    Perl data structures
  14. <li><A HREF="perlsyn.html">perlsyn</A>    Perl syntax
  15. <li><A HREF="perlop.html">perlop</A>    Perl operators and precedence
  16. <li><A HREF="perlre.html">perlre</A>    Perl regular expressions
  17. <li><A HREF="perlrun.html">perlrun</A>    Perl execution and options
  18. <li><A HREF="perlfunc.html">perlfunc</A>    Perl builtin functions
  19. <li><A HREF="perlvar.html">perlvar</A>    Perl predefined variables
  20. <li><A HREF="perlsub.html">perlsub</A>    Perl subroutines
  21. <li><A HREF="perlmod.html">perlmod</A>    Perl modules
  22. <li><A HREF="perlref.html">perlref</A>    Perl references and nested data structures
  23. <li><A HREF="perlobj.html">perlobj</A>    Perl objects
  24. <li><A HREF="perlbot.html">perlbot</A>    Perl OO tricks and examples
  25. <li><A HREF="perldebug.html">perldebug</A>    Perl debugging
  26. <li><A HREF="perldiag.html">perldiag</A>    Perl diagnostic messages
  27. <li><A HREF="perlform.html">perlform</A>    Perl formats
  28. <li><A HREF="perlipc.html">perlipc</A>    Perl interprocess communication
  29. <li><A HREF="perlsec.html">perlsec</A>    Perl security
  30. <li><A HREF="perltrap.html">perltrap</A>    Perl traps for the unwary
  31. <li><A HREF="perlstyle.html">perlstyle</A>    Perl style guide
  32. <li><A HREF="perlapi.html">perlapi</A>    Perl application programming interface
  33. <li><A HREF="perlguts.html">perlguts</A>    Perl internal functions for those doing extensions 
  34. <li><A HREF="perlcall.html">perlcall</A>    Perl calling conventions from C
  35. <li><A HREF="perlovl.html">perlovl</A>    Perl overloading semantics
  36. <li><A HREF="perlbook.html">perlbook</A>    Perl book information
  37. </ul>
  38. (If you're intending to read these straight through for the first time,
  39. the suggested order will tend to reduce the number of forward references.)
  40. <p>If something strange has gone wrong with your program and you're not
  41. sure where you should look for help, try the 
  42. <A HREF="perlrun.html#perlrun_362">-w</A>
  43.  switch first.  It
  44. will often point out exactly where the trouble is.
  45. <p><h2>DESCRIPTION</h2>
  46. Perl is an interpreted language optimized for scanning arbitrary
  47. text files, extracting information from those text files, and printing
  48. reports based on that information.  It's also a good language for many
  49. system management tasks.  The language is intended to be practical
  50. (easy to use, efficient, complete) rather than beautiful (tiny,
  51. elegant, minimal).  It combines (in the author's opinion, anyway) some
  52. of the best features of C, <B>sed</B>, <B>awk</B>, and <B>sh</B>, so people
  53. familiar with those languages should have little difficulty with it.
  54. (Language historians will also note some vestiges of <B>csh</B>, Pascal,
  55. and even BASIC-PLUS.)  Expression syntax corresponds quite closely to C
  56. expression syntax.  Unlike most Unix utilities, Perl does not
  57. arbitrarily limit the size of your data--if you've got the memory,
  58. Perl can slurp in your whole file as a single string.  Recursion is
  59. of unlimited depth.  And the hash tables used by associative arrays
  60. grow as necessary to prevent degraded performance.  Perl uses
  61. sophisticated pattern matching techniques to scan large amounts of data
  62. very quickly.  Although optimized for scanning text, Perl can also
  63. deal with binary data, and can make dbm files look like associative
  64. arrays (where dbm is available).  Setuid Perl scripts are safer than
  65. C programs through a dataflow tracing mechanism which prevents many
  66. stupid security holes.  If you have a problem that would ordinarily use
  67. <B>sed</B> or <B>awk</B> or <B>sh</B>, but it exceeds their capabilities or must
  68. run a little faster, and you don't want to write the silly thing in C,
  69. then Perl may be for you.  There are also translators to turn your
  70. <B>sed</B> and <B>awk</B> scripts into Perl scripts.
  71. <p>But wait, there's more...
  72. <p>Perl version 5 is nearly a complete rewrite, and provides
  73. the following additional benefits:
  74. <p>
  75. <dl>
  76.  
  77. <dt><b><A NAME="perlcall_39">* Many usability enhancements</A></b>
  78. <dd>
  79. It is now possible to write much more readable Perl code (even within
  80. regular expressions).  Formerly cryptic variable names can be replaced
  81. by mnemonic identifiers.  Error messages are more informative, and the
  82. optional warnings will catch many of the mistakes a novice might make.
  83. This cannot be stressed enough.  Whenever you get mysterious behavior,
  84. try the 
  85. <A HREF="perlrun.html#perlrun_362">-w</A>
  86.  switch!!!  Whenever you don't get mysterious behavior,
  87. try using 
  88. <A HREF="perlrun.html#perlrun_362">-w</A>
  89.  anyway.
  90. <p></dd>
  91. <dt><B>* Simplified grammar</B>
  92. <dd>
  93. The new yacc grammar is one half the size of the old one.  Many of the
  94. arbitrary grammar rules have been regularized.  The number of reserved
  95. words has been cut by 2/3.  Despite this, nearly all old Perl scripts
  96. will continue to work unchanged.
  97. <p></dd>
  98. <dt><B>* Lexical scoping</B>
  99. <dd>
  100. Perl variables may now be declared within a lexical scope, like "auto"
  101. variables in C.  Not only is this more efficient, but it contributes
  102. to better privacy for "programming in the large".
  103. <p></dd>
  104. <dt><B>* Arbitrarily nested data structures</B>
  105. <dd>
  106. Any scalar value, including any array element, may now contain a
  107. reference to any other variable or subroutine.  You can easily create
  108. anonymous variables and subroutines.  Perl manages your reference
  109. counts for you.
  110. <p></dd>
  111. <dt><B>* Modularity and reusability</B>
  112. <dd>
  113. The Perl library is now defined in terms of modules which can be easily
  114. shared among various packages.  A package may choose to import all or a
  115. portion of a module's published interface.  Pragmas (that is, compiler
  116. directives) are defined and used by the same mechanism.
  117. <p></dd>
  118. <dt><B>* Object-oriented programming</B>
  119. <dd>
  120. A package can function as a class.  Dynamic multiple inheritance and
  121. virtual methods are supported in a straightforward manner and with very
  122. little new syntax.  Filehandles may now be treated as objects.
  123. <p></dd>
  124. <dt><B>* Embeddible and Extensible</B>
  125. <dd>
  126. Perl may now be embedded easily in your C or C++ application, and can
  127. either call or be called by your routines through a documented
  128. interface.  The XS preprocessor is provided to make it easy to glue
  129. your C or C++ routines into Perl.  Dynamic loading of modules is
  130. supported.
  131. <p></dd>
  132. <dt><B>* POSIX compliant</B>
  133. <dd>
  134. A major new module is the POSIX module, which provides access to all
  135. available POSIX routines and definitions, via object classes where
  136. appropriate.
  137. <p></dd>
  138. <dt><B>* Package constructors and destructors</B>
  139. <dd>
  140. The new BEGIN and END blocks provide means to capture control as
  141. a package is being compiled, and after the program exits.  As a
  142. degenerate case they work just like awk's BEGIN and END when you
  143. use the 
  144. <A HREF="perlrun.html#perlrun_354">-p</A>
  145.  or 
  146. <A HREF="perlrun.html#perlrun_353">-n</A>
  147.  switches.
  148. <p></dd>
  149. <dt><B>* Multiple simultaneous DBM implementations</B>
  150. <dd>
  151. A Perl program may now access DBM, NDBM, SDBM, GDBM, and Berkeley DB
  152. files from the same script simultaneously.  In fact, the old dbmopen
  153. interface has been generalized to allow any variable to be tied
  154. to an object class which defines its access methods.
  155. <p></dd>
  156. <dt><B>* Subroutine definitions may now be autoloaded</B>
  157. <dd>
  158. In fact, the AUTOLOAD mechanism also allows you to define any arbitrary
  159. semantics for undefined subroutine calls.  It's not just for autoloading.
  160. <p></dd>
  161. <dt><B>* Regular expression enhancements</B>
  162. <dd>
  163. You can now specify non-greedy quantifiers.  You can now do grouping
  164. without creating a backreference.  You can now write regular expressions
  165. with embedded whitespace and comments for readability.  A consistent
  166. extensibility mechanism has been added that is upwardly compatible with
  167. all old regular expressions.
  168. <p></dd>
  169.  
  170. </dl>
  171.  
  172. Ok, that's <I>definitely</I> enough hype.
  173. <p><h2>ENVIRONMENT</h2>
  174.  
  175. <dl>
  176. <dt><B>HOME</B>
  177. <dd>
  178. Used if chdir has no argument.
  179. <p></dd>
  180. <dt><B>LOGDIR</B>
  181. <dd>
  182. Used if chdir has no argument and HOME is not set.
  183. <p></dd>
  184. <dt><B>PATH</B>
  185. <dd>
  186. Used in executing subprocesses, and in finding the script if 
  187. <A HREF="perlrun.html#perlrun_357">-S</A>
  188.  is
  189. used.
  190. <p></dd>
  191. <dt><B>PERL5LIB</B>
  192. <dd>
  193. A colon-separated list of directories in which to look for Perl library
  194. files before looking in the standard library and the current
  195. directory.  If PERL5LIB is not defined, PERLLIB is used.
  196. <p></dd>
  197. <dt><B>PERL5DB</B>
  198. <dd>
  199. The command used to get the debugger code.  If unset, uses
  200. <p></dd>
  201. <pre>
  202.         BEGIN { require 'perl5db.pl' }
  203. </pre>
  204. <dt><B>PERLLIB</B>
  205. <dd>
  206. A colon-separated list of directories in which to look for Perl library
  207. files before looking in the standard library and the current
  208. directory.  If PERL5LIB is defined, PERLLIB is not used.
  209. <p></dd>
  210.  
  211. </dl>
  212.  
  213. Apart from these, Perl uses no other environment variables, except
  214. to make them available to the script being executed, and to child
  215. processes.  However, scripts running setuid would do well to execute
  216. the following lines before doing anything else, just to keep people
  217. honest:
  218. <p><pre>
  219.         $ENV{'PATH'} = '/bin:/usr/bin';    # or whatever you need
  220.         $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'};
  221.         $ENV{'IFS'} = ''          if defined $ENV{'IFS'};
  222. </pre>
  223. <h2>AUTHOR</h2>
  224. Larry Wall <<I>lwall@netlabs.com.</I>, with the help of oodles of other folks.
  225. <p><h2>FILES</h2>
  226. <pre>
  227.      "/tmp/perl-e$$"    temporary file for -e commands
  228.      "@INC"                     locations of perl 5 libraries
  229. </pre>
  230. <h2>SEE ALSO</h2>
  231.  
  232. <listing>
  233.  a2p    awk to perl translator 
  234.  s2p    sed to perl translator 
  235. </listing>
  236. <h2>DIAGNOSTICS</h2>
  237. The 
  238. <A HREF="perlrun.html#perlrun_362">-w</A>
  239.  switch produces some lovely diagnostics.
  240. <p>See 
  241. <A HREF="perldiag.html">
  242. the perldiag manpage</A>
  243.  for explanations of all Perl's diagnostics.
  244. <p>Compilation errors will tell you the line number of the error, with an
  245. indication of the next token or token type that was to be examined.
  246. (In the case of a script passed to Perl via 
  247. <A HREF="perlrun.html#perlrun_348">-e</A>
  248.  switches, each
  249.  
  250. <A HREF="perlrun.html#perlrun_348">-e</A>
  251.  is counted as one line.)
  252. <p>Setuid scripts have additional constraints that can produce error
  253. messages such as "Insecure dependency".  See 
  254. <A HREF="perlsec.html">
  255. the perlsec manpage</A>
  256. .
  257. <p>Did we mention that you should definitely consider using the 
  258. <A HREF="perlrun.html#perlrun_362">-w</A>
  259.  
  260. switch?
  261. <p><h2>BUGS</h2>
  262. The 
  263. <A HREF="perlrun.html#perlrun_362">-w</A>
  264.  switch is not mandatory.
  265. <p>Perl is at the mercy of your machine's definitions of various
  266. operations such as type casting, atof() and sprintf().
  267. <p>If your stdio requires an seek or eof between reads and writes on a
  268. particular stream, so does Perl.  (This doesn't apply to sysread()
  269. and syswrite().)
  270. <p>While none of the built-in data types have any arbitrary size limits
  271. (apart from memory size), there are still a few arbitrary limits:  a
  272. given identifier may not be longer than 255 characters, and no
  273. component of your PATH may be longer than 255 if you use 
  274. <A HREF="perlrun.html#perlrun_357">-S</A>
  275. .  A regular
  276. expression may not compile to more than 32767 bytes internally.
  277. <p>Perl actually stands for Pathologically Eclectic Rubbish Lister, but
  278. don't tell anyone I said that.
  279. <p><h2>NOTES</h2>
  280. The Perl motto is "There's more than one way to do it."  Divining
  281. how many more is left as an exercise to the reader.
  282. <p>The three principle virtues of a programmer are Laziness,
  283. Impatience, and Hubris.  See the Camel Book for why.<p>